﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StudentWeb.DAL;
using StudentWeb.Model;
using StudentWeb.Common;

namespace StudentWeb.BLL
{
    public class CatBO
    {
        #region 猫猫信息 单条记录
        /// <summary>
        /// 书籍信息 单条记录
        /// </summary>
        /// <param name="CatID"></param>
        /// <returns></returns>
        public IResult GetCatInfo(int catID)
        {
            var res = new CatDataLLJJDAO().GetInfo(catID);
            return new DataResult<CatDataLLJJ>(res);
        }
        #endregion
        #region 猫猫信息 添加
        public bool InsertCatInfo(dynamic data)
        {
            var result = 0;
            var cat = new CatDataLLJJ()
            {
                CatNameLLJJ = data.CatNameLLJJ,
                CatSexLLJJ = data.CatSexLLJJ,
            };
            result = new CatDataLLJJDAO().Insert(cat);

            return result > 0;
        }

        #endregion
        #region 猫猫信息 更新
        public bool UpdateCatInfo(dynamic data)
        {
            int CatDataIDLLJJ = data.CatDataIDLLJJ;
            var result = 0;
            var record = new CatDataLLJJDAO().GetInfo(CatDataIDLLJJ);
            record.CatNameLLJJ = data.CatNameLLJJ;
            record.CatSexLLJJ = data.CatSexLLJJ;
            result = new CatDataLLJJDAO().Update(record);
            return result > 0;
        }
        #endregion
        #region 猫猫信息 保存单条记录
        public bool SaveCatInfo(dynamic data)
        {
            int CatDataIDLLJJ = data.CatDataIDLLJJ ?? 0;
            var result = 0;
            if (CatDataIDLLJJ > 0)
            {
                var record = new CatDataLLJJDAO().GetInfo(CatDataIDLLJJ);
                record.CatNameLLJJ = data.CatNameLLJJ;
                record.CatSexLLJJ= data.CatSexLLJJ;
                result = new CatDataLLJJDAO().Update(record);
            }
            else if (CatDataIDLLJJ == 0)
            {
                var cat = new CatDataLLJJ()
                {
                    CatNameLLJJ = data.CatNameLLJJ,
                    CatSexLLJJ = data.CatSexLLJJ,
                };
                result = new CatDataLLJJDAO().Insert(cat);

            }
            return result > 0;

        }
        #endregion
        #region 猫猫信息 删除记录
        public IResult DeleteCatInfo(int CatDateIDLLJJ)
        {
            int res = new CatDataLLJJDAO().Delete(CatDateIDLLJJ);
            if (res > 0)
            {
                return new Result(ResultCode.Success);
            }
            return new Result(ResultCode.Fail);
        }
        #endregion
        #region 查询书籍列表
        public IResult GetCatList()
        {
            var list = new CatDataLLJJDAO().GetList();
            return new DataResult(list);
        }
        #endregion
        #region 猫猫信息 分页列表
        /// <summary>
        /// 猫猫信息 分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="wc"></param>
        /// <returns></returns>
        public IResult GetCatList(int pageIndex, int pageSize, string wc = null)
        {
            var list = new CatDataLLJJDAO().GetCatList(pageIndex, pageSize, wc);
            return new DataResult<PagedList<dynamic>>(list);
        }
        #endregion
    }
}
